﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_file_edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CFile f = new CFile();
            DataTable dt = f.ReadFiles(0);
            if (null != dt)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    this.ddlType.Items.Add(new ListItem(dt.Rows[i]["title"].ToString(), dt.Rows[i]["id"].ToString()));
                }
            }
            if (null != Request.QueryString["s"])
            {
                this.ddlType.SelectedValue = Request.QueryString["s"].ToString();
                this.ddlType.Enabled = false;
            }
            if (null != Request.QueryString["id"])
            {
                //更新
                DataRow r = f.ReadFile(Convert.ToInt32(Request.QueryString["id"].ToString()));
                if (null != r)
                {
                    this.ddlType.SelectedValue = r["parent"].ToString();
                    this.tbTitle.Text = r["title"].ToString();
                }
            }
        }
    }

    protected void btnOk_Click(object sender, EventArgs e)
    {
        CFile f = new CFile();
        if (null != Request.QueryString["id"])
        {
            //更新
            f.Update(Convert.ToInt32(Request.QueryString["id"].ToString()), this.tbTitle.Text);
        }
        else
        {
            //添加
            f.Add(this.tbTitle.Text, Convert.ToInt32(this.ddlType.SelectedValue), "0");
        }
        ScriptManager.RegisterClientScriptBlock(Page, upEdit.GetType(), "", "alert('操作完成!');", true);
    }

    protected void btnOk1_Click(object sender, EventArgs e)
    {
        //妈的，为什么要提交两次才能获取到内容，耽误时间啊，用户体验啊，Shit!!!
    }
}